package com.yixun.qfbao.hander;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qiaofang.common.util.StringUtil;
import com.yixun.qfbao.apidto.GetAgentInfoResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.dto.CompanyDto;
import com.yixun.qfbao.service.CompanyService;
import com.yixun.qfbao.vo.GetAgentInfoReqVo;
import com.yixun.qfbao.vo.UpdateCompanyAbbreviationReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;

/**
 * @author zilong.liu
 * @date 2020-12-16
 *
 * desc:
 *     	根据经纪人的手机号以及总代companyUuid获取对应的经纪人信息
 */
@Service("getAgentInfoHander")
public class GetAgentInfoHander extends CommonAbstractHander{

	@Autowired
	CompanyService companyService;
	
	@SuppressWarnings("rawtypes")
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		GetAgentInfoReqVo reqVo = (GetAgentInfoReqVo) reqDto;
		String phone = reqVo.getParams().getPhone();
		String companyUuid = reqVo.getParams().getCompanyUuid();
		
		BaseResponseDTO res = new BaseResponseDTO();
		
		Map<String, Object> agentInfo = companyService.getAgentInfo(phone, companyUuid);
		
		if(agentInfo == null) {
			res.setResult(ResultEnum.FAIL.getNo());
			res.setResult("未查询到对应的账号信息");
			return res;
		}
		GetAgentInfoResDto getAgentInfoResDto = new GetAgentInfoResDto();
		getAgentInfoResDto.setAgentCompanyId(String.valueOf(agentInfo.get("company_id")));
		getAgentInfoResDto.setAgentCompanyName(String.valueOf(agentInfo.get("company_name")));
		getAgentInfoResDto.setAgentCompanyUuid(String.valueOf(agentInfo.get("company_uuid")));
		getAgentInfoResDto.setPartnerId(Long.parseLong(String.valueOf(agentInfo.get("partner_id"))));
		getAgentInfoResDto.setPartnerName(String.valueOf(agentInfo.get("account_name")));
		
		res.setResData(getAgentInfoResDto);
		res.setResult(ResultEnum.SUCCESS.getNo());
		return res;
	}

}
